﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace WeatherHistory.Data.Migrations
{
    /// <inheritdoc />
    public partial class FixedRelationTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_WeatherForecastRelation_Forecasts_ForecastId",
                table: "WeatherForecastRelation");

            migrationBuilder.DropForeignKey(
                name: "FK_WeatherForecastRelation_Weathers_WeatherId",
                table: "WeatherForecastRelation");

            migrationBuilder.DropForeignKey(
                name: "FK_WeatherRegionRelation_Regions_RegionId",
                table: "WeatherRegionRelation");

            migrationBuilder.DropForeignKey(
                name: "FK_WeatherRegionRelation_Weathers_WeatherId",
                table: "WeatherRegionRelation");

            migrationBuilder.DropPrimaryKey(
                name: "PK_WeatherRegionRelation",
                table: "WeatherRegionRelation");

            migrationBuilder.DropPrimaryKey(
                name: "PK_WeatherForecastRelation",
                table: "WeatherForecastRelation");

            migrationBuilder.RenameTable(
                name: "WeatherRegionRelation",
                newName: "WeatherRegionRelations");

            migrationBuilder.RenameTable(
                name: "WeatherForecastRelation",
                newName: "WeatherForecastRelations");

            migrationBuilder.RenameIndex(
                name: "IX_WeatherRegionRelation_WeatherId",
                table: "WeatherRegionRelations",
                newName: "IX_WeatherRegionRelations_WeatherId");

            migrationBuilder.RenameIndex(
                name: "IX_WeatherForecastRelation_WeatherId",
                table: "WeatherForecastRelations",
                newName: "IX_WeatherForecastRelations_WeatherId");

            migrationBuilder.AlterColumn<decimal>(
                name: "Longitude",
                table: "Regions",
                type: "numeric(38,17)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric");

            migrationBuilder.AlterColumn<decimal>(
                name: "Latitude",
                table: "Regions",
                type: "numeric(38,17)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric");

            migrationBuilder.AddPrimaryKey(
                name: "PK_WeatherRegionRelations",
                table: "WeatherRegionRelations",
                columns: new[] { "RegionId", "WeatherId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_WeatherForecastRelations",
                table: "WeatherForecastRelations",
                columns: new[] { "ForecastId", "WeatherId" });

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherForecastRelations_Forecasts_ForecastId",
                table: "WeatherForecastRelations",
                column: "ForecastId",
                principalTable: "Forecasts",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherForecastRelations_Weathers_WeatherId",
                table: "WeatherForecastRelations",
                column: "WeatherId",
                principalTable: "Weathers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherRegionRelations_Regions_RegionId",
                table: "WeatherRegionRelations",
                column: "RegionId",
                principalTable: "Regions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherRegionRelations_Weathers_WeatherId",
                table: "WeatherRegionRelations",
                column: "WeatherId",
                principalTable: "Weathers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_WeatherForecastRelations_Forecasts_ForecastId",
                table: "WeatherForecastRelations");

            migrationBuilder.DropForeignKey(
                name: "FK_WeatherForecastRelations_Weathers_WeatherId",
                table: "WeatherForecastRelations");

            migrationBuilder.DropForeignKey(
                name: "FK_WeatherRegionRelations_Regions_RegionId",
                table: "WeatherRegionRelations");

            migrationBuilder.DropForeignKey(
                name: "FK_WeatherRegionRelations_Weathers_WeatherId",
                table: "WeatherRegionRelations");

            migrationBuilder.DropPrimaryKey(
                name: "PK_WeatherRegionRelations",
                table: "WeatherRegionRelations");

            migrationBuilder.DropPrimaryKey(
                name: "PK_WeatherForecastRelations",
                table: "WeatherForecastRelations");

            migrationBuilder.RenameTable(
                name: "WeatherRegionRelations",
                newName: "WeatherRegionRelation");

            migrationBuilder.RenameTable(
                name: "WeatherForecastRelations",
                newName: "WeatherForecastRelation");

            migrationBuilder.RenameIndex(
                name: "IX_WeatherRegionRelations_WeatherId",
                table: "WeatherRegionRelation",
                newName: "IX_WeatherRegionRelation_WeatherId");

            migrationBuilder.RenameIndex(
                name: "IX_WeatherForecastRelations_WeatherId",
                table: "WeatherForecastRelation",
                newName: "IX_WeatherForecastRelation_WeatherId");

            migrationBuilder.AlterColumn<decimal>(
                name: "Longitude",
                table: "Regions",
                type: "numeric",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric(38,17)");

            migrationBuilder.AlterColumn<decimal>(
                name: "Latitude",
                table: "Regions",
                type: "numeric",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "numeric(38,17)");

            migrationBuilder.AddPrimaryKey(
                name: "PK_WeatherRegionRelation",
                table: "WeatherRegionRelation",
                columns: new[] { "RegionId", "WeatherId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_WeatherForecastRelation",
                table: "WeatherForecastRelation",
                columns: new[] { "ForecastId", "WeatherId" });

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherForecastRelation_Forecasts_ForecastId",
                table: "WeatherForecastRelation",
                column: "ForecastId",
                principalTable: "Forecasts",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherForecastRelation_Weathers_WeatherId",
                table: "WeatherForecastRelation",
                column: "WeatherId",
                principalTable: "Weathers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherRegionRelation_Regions_RegionId",
                table: "WeatherRegionRelation",
                column: "RegionId",
                principalTable: "Regions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_WeatherRegionRelation_Weathers_WeatherId",
                table: "WeatherRegionRelation",
                column: "WeatherId",
                principalTable: "Weathers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
